package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.po.Button;
import com.zhijian.medical.entity.po.RoleMenu;
import com.zhijian.medical.entity.vo.request.ButtonSearchVo;
import com.zhijian.medical.entity.vo.request.MenuSearchVo;
import com.zhijian.medical.entity.vo.request.RoleSearchVo;
import com.zhijian.medical.entity.vo.response.ButtonVo;
import com.zhijian.medical.entity.vo.response.MenuVo;
import com.zhijian.medical.entity.vo.response.RoleVo;
import com.zhijian.medical.service.ButtonService;
import com.zhijian.medical.service.MenuService;
import com.zhijian.medical.service.RoleMenuService;
import com.zhijian.medical.service.RoleService;
import com.zhijian.medical.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 按钮 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2022-01-23 15:36:11
 */
@Slf4j
@Controller
@Api(tags = "按钮")
public class ButtonController {

    @Autowired
    private ButtonService service;

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/button")
    @ApiOperation("新增")
    public boolean insert(@RequestBody Button param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.insert(param) != null;
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/button/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/button/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody Button param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.update(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/button/{id}")
    @ApiOperation("根据id查询")
    public ButtonVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/button/page")
    @ApiOperation("分页查询")
    public Page<ButtonVo> selectByCondition(@RequestBody(required = false) ButtonSearchVo param) {
        if (param == null)
            param = ButtonSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

}